import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css
import '@/assets/font/iconfont.css' // icon
import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
import * as COM from '@/api/common.js'
import './utils/request.js'

import * as filters from './filters' // global filters

import VueI18n from "vue-i18n";
import VueEditor from "vue2-editor";
Vue.use(VueI18n);
Vue.use(VueEditor);
import FormMaking from "./index";
Vue.use(FormMaking);
Vue.prototype.COM = COM
// const on = Vue.prototype.$on

// 节流
// Vue.prototype.$on = function (event, func) {
//   let previous = 0
//   let newFunc = func
//   console.log(1111111)
//   if (event === 'click') {
//     newFunc = function () {
//       const now = new Date().getTime()
//       if (previous + 5000 <= now) {
//         func.apply(this, arguments)
//         previous = now
//       }
//     }
//   }
//   on.call(this, event, newFunc)
// }

// // 防抖处理
// Vue.prototype.$on = function (event, func) {
//   let timer
//   let newFunc = func
//   if (event === 'click') {
//     newFunc = function () {
//       clearTimeout(timer)
//       timer = setTimeout(function () {
//         func.apply(this, arguments)
//       }, 5000)
//     }
//   }
//   on.call(this, event, newFunc)
// }

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

Vue.use(Element, {
  size: Cookies.get('size') || 'mini' // set element-ui default size
  // locale: enLang // 如果使用中文，无需设置，请删除
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
